import { get, set, remove } from '@/utils/localStorage'

export default {
	namespaced: true,
    state: {
        // userInfo: JSON.parse(uni.getStorageSync('USER')　|| '{}'),
        userInfo: {
			isLogin: false,
			token: 'nskajgksmegf1541512sefawfbaiwbkjsneqw3e3',
			access: ['superAdmim', 'admin'],
		},
    },
    mutations: {
        updateAccess(state:any, access:any) {
            if (access !== undefined && access !== null) {
                state.userInfo.access = access;
                set('ACCESS_KEY', JSON.stringify(access));
            } else {
                state.userInfo.access = [];
            }
        },
        updateUser(state:any, value:any) {
            if (value !== undefined && value !== null) {
                state.userInfo = value;
                set('USER', JSON.stringify(value));
            } else {
                state.userInfo = {};
				remove('USER');
            }
        },
    },
    getters: {
		userInfo: (state:any, getters:any, rootState:any) => state.userInfo,
	},
    actions: {},
};
